<template>
  <div class="swiper-container" v-if="Object.keys(bannerData)">
    <div class="swiper-wrapper">
      <div class="swiper-slide" v-for="item in bannerData" :key="item.bannerId">
        <img :src="item.imgUrl" alt="" />
      </div>
    </div>
    <!-- 如果需要分页器 -->
    <div class="swiper-pagination"></div>

    <!-- 如果需要导航按钮 -->
    <!-- <div class="swiper-button-prev"></div>
    <div class="swiper-button-next"></div> -->

    <!-- 如果需要滚动条 -->
    <!--    <div class="swiper-scrollbar"></div>-->
  </div>
</template>

<script>
import Swiper from 'swiper'
export default {
  name: 'Swiper',
  props: ['bannerData'],
  updated() {
    new Swiper('.swiper-container', {
      loop: true,
      // 如果需要分页器
      pagination: {
        el: '.swiper-pagination'
      },
      autoplay: {
        delay: 3000,
        disableOnInteraction: false
      }
    })
  }
}
</script>

<style lang="scss" scoped>
.swiper-container {
  height: 1.95rem;
  width: 100%;
  .swiper-wrapper {
    .swiper-slide {
      width: 100%;
      height: 100%;
      text-align: center;
      line-height: 1.95rem;
      img {
        width: 100%;
        height: 100%;
      }
    }
  }
}
</style>